<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>字符串出现次数最多</title>
</head>
<body>
    

    <script>
    
        var str = 'aaabbbccccccc';

        function findStr(str) {
            var obj = {};
            for(var i=0;i<str.length;i++){
                if(!obj[str[i]]){
                    obj[str[i]] = 1;
                }else{
                    obj[str[i]] ++;
                }
            }
            var arr = [];
            var _max = 0;
            for(var key in obj){
                arr.push(obj[key]);
                obj[key]>_max?_max=obj[key]:null;
                var item = key;
            }

            return `出现次数最多的字符是${item},出现次数为${_max}`
        }

        console.log(findStr(str));


    </script>
</body>
</html>